#ifndef GITUPDATERQML_H
#define GITUPDATERQML_H

#include <QObject>
#include "gitupdater.h"
#include "git2updater.h"
#include "source/versioninfo.h"

class gitUpdaterQML : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString currentVersionInfo READ getcurrentVersionInfo NOTIFY getcurrentVersionInfoChanged)
    Q_PROPERTY(QString currentVersion READ currentVersion)
public:
    static gitUpdaterQML& instance()
    {
        static gitUpdaterQML instance;
        return instance;
    }

    Q_INVOKABLE void getCurrentVersion(); //不可用
    Q_INVOKABLE void getLatestVersion();
    Q_INVOKABLE void startUpdate();

    QString currentVersion() const {return currentVersionInfo.split("\n")[1];};
    QString getcurrentVersionInfo() const {return currentVersionInfo;};
signals:
    // details["version"] ["description"] ["date"]
    // ["error"]
    // ["message"]
    void getcurrentVersionInfoChanged();//
    void response(bool success, const QVariantMap &details);
    void updateProgress(int progress);//0-100response

private:
    gitUpdaterQML(QObject *parent = nullptr);
    ~gitUpdaterQML();

    Git2Updater *m_git2Updater;
    QThread *m_thread;
    //gitUpdater *m_updater;
};

#endif // GITUPDATERQML_H
